#ifndef __ALGORITHM__H
#define __ALGORITHM__H
#include "Emm_V5.h"
#include <stdbool.h>
#define USE_USART
// #define USE_CAN
typedef struct 
{
    uint8_t addr;//电机地址
    uint8_t dir; //方向
    uint16_t vel; //速度
    uint8_t acc; //加速度
    uint32_t clk; //脉冲数
    bool raF; //相对运动或绝对运动
    bool snF;//多机同步标志
    float angle;//电机设置角度
    uint32_t temp;//脉冲数
}STEP_MOTOR;

extern STEP_MOTOR motor1;
extern STEP_MOTOR motor2;

extern STEP_MOTOR *arr[2];

void step_struct_init(STEP_MOTOR *motor,uint8_t addr_set,uint8_t dir_set,uint16_t vel_set,uint8_t acc_set,uint32_t clk_set,bool raF_set,bool snF_set);
void step_struct_deinit(STEP_MOTOR *motor);
void step_struct_setaddr(STEP_MOTOR *motor, uint8_t addr_set);
void step_struct_setdir(STEP_MOTOR *motor, uint8_t dir_set);
void step_struct_setvel(STEP_MOTOR *motor, uint16_t vel_set);
void step_struct_setacc(STEP_MOTOR *motor, uint8_t acc_set);
void step_struct_setclk(STEP_MOTOR *motor, uint32_t clk_set);
void step_struct_setraF(STEP_MOTOR *motor, bool raF_set);
void step_struct_setsnF(STEP_MOTOR *motor, bool snF_set);
void step_struct_setangle(STEP_MOTOR *motor,float angle_set);
void step_struct_settemp(STEP_MOTOR *motor,uint32_t temp);
void multiple_step_syn_position_ctrl(STEP_MOTOR* motor[], uint8_t num);
float step_read_real_position(STEP_MOTOR* motor);
void step_position_ctrl(STEP_MOTOR* motor);
void step_vel_ctrl(STEP_MOTOR* motor);
void multiple_step_syn_vel_ctrl(STEP_MOTOR* motor[], uint8_t num);// 此函数最后命令返回需要验证
float step_read_real_vel(STEP_MOTOR* motor);
void step_backzero(STEP_MOTOR* motor);
void step_zero_set_nosave(STEP_MOTOR* motor);
void step_angle_ctrl(STEP_MOTOR* motor);
void multiple_step_syn_angle_ctrl(STEP_MOTOR * motor[], uint8_t num);
#endif 